<template>
  <el-card class="box-card">
    <div class="title" v-if="title">{{ title }}</div>
    <!-- 文章排行列表 -->
    <ul class="article-rank-wrapper">
      <li v-for="(item, index) in rank" :key="item._id" @click="handleItemClick(index)">
        <div class="rank-item-index">{{ index + 1 }}.</div>
        <div class="rank-item-title">{{ item.title }}</div>
        <div class="rank-item-num" v-if="showReadCount">阅读量:{{ item.readCount }}</div>
      </li>
    </ul>
  </el-card>
</template>

<script>
export default {
  name: 'ArticleRankCard',
  props: {
    rank: {
      type: Array,
      default: () => []
    },
    title: {
      type: String
    },
    showReadCount: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {

    }
  },
  methods: {
    handleItemClick(index) {
      this.$emit('item', index)
    }
  }
}
</script>

<style lang="scss" scoped>
.title {
  font-size: 14pt;
  font-weight: bold;
  // border-bottom: solid 1px black;
  padding-bottom: 14px;
}

.article-rank-wrapper {
  padding: 0;
  margin: 0;
  list-style: none;

  &>li {
    display: flex;
    flex-direction: row;
    // margin: 8px 0;
    padding: 6px 0;
    cursor: pointer;
    font-size: 12pt;
    color: var(--el-text-color-primary);

    .rank-item-index {
      width: 28px;
      padding-right: 12px;
      text-align: end;
      color: var(--el-text-color-regular);
    }

    .rank-item-title {
      flex: 1;
      padding-right: 10px;
    }

    .rank-item-num {
      width: 80px;
      font-size: 11pt;
      color: var(--el-text-color-secondary);
    }
  }
}
</style>
